<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function add(a, b) {
        // 获取最大长度
        let maxLength = Math.max(a.length, b.length);
        // 补零
        a = a.padStart(maxLength, "0");
        b = b.padStart(maxLength, "0");
        // 暂时需要的变量
        let res = ""; // 最终结果
        let f = 0; // 进位
        let curr = 0; // 当前项的值
        // 遍历
        for (let i = maxLength - 1; i >= 0; i--) {
          // 两个字符相加
          curr = parseInt(a.charAt(i)) + parseInt(b.charAt(i)) + f;
          // 取出进位
          f = Math.floor(curr / 10);
          // 除去进位之后的当前值，字符串拼接
          res = (curr % 10) + res;
        }
        // 如果还有进位则要加上,只可能有一位进位
        if (f === 1) {
          res = f + res;
        }
        return res;
      }

      let a = "9007199254740991";
      let b = "1234567899999999999";
			console.log(add(a ,b));  // 1243575099254740990
    </script>
  </body>
</html>
